<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\validate;
use think\Validate;
use think\Db;
//修改会员余额验证
class UpdateMoneyValidate extends Validate
{
    protected $rule = [
        'user_id'       => 'require|number',
        'type_id'        => 'require|number',
        'money'        => 'require|isMoney',
        'ramakr'        => 'require|length:2,30',

    ];

    protected $message = [
        'user_id'       => '会员id必传',
        'update_money'        => '修改类型必传',
        'money'        => '请输入金额',
        'ramakr'        => '请输入2-30个备注',
    ];

    //验证类型存在不
    protected function type($val)
    {
        $statue = false;
        foreach (config('update_type') as $item) {
            if($item['val'] == $val){
                $statue = true;
            }
        }

        if ($statue) return true;
        else return '修改类型不存在';
    }
    
    //验证钱格式

    /**
     * @param $val
     * @return bool|string10
     * 可用格式有 下面
        -10
        -1.00
        -10.10
        10.00
     */
    public function isMoney($val)
    {

        if(preg_match("/^(\d|-\d)*\.{0,1}\d{0,2}$/",$val) && !empty($val)){
            return true;
        }else{
            return '钱的格式不符合';
        }
    }
}